package com.interview.item.javabase.json;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashMap;

/**
 * @Author:zxh
 * @Description:
 * @Date: 2020/4/4
 * @Modified By:
 */
public class JsonDemo {
    static Logger logger = LoggerFactory.getLogger(JsonDemo.class);

    public static void main(String[] args) {
        JsonClass jsonClass = new JsonClass();
        HashMap<String, Object> hashMap = new HashMap<>();
        hashMap.put("one", "one");
        hashMap.put("two", 22);
        hashMap.put("three", "three");
        jsonClass.setKey("sessionId", JSON.toJSONString(hashMap));

        if (jsonClass.getKey().equals("sessionId")) {
            logger.info("输出：{}", jsonClass.getValue());
        }

        String sessionpk = jsonClass.getKey("sessionId");
        logger.info("输出pk：{}", sessionpk);
        JSONObject jsonObject = JSON.parseObject(sessionpk);
        String one = (String) jsonObject.get("one");
        Integer two = (Integer) jsonObject.get("two");
        logger.info("输出value:{},  two:{}", one, two);
        jsonObject.put("four", "four");
        jsonClass.setKey("sessionId", jsonObject.toJSONString());

        String sessionpkT = jsonClass.getKey("sessionId");
        JSONObject jsonObjectT = JSON.parseObject(sessionpkT);
        String oneT = (String) jsonObjectT.get("one");
        String four = (String) jsonObjectT.get("four");
        logger.info("输出2value:{},  four:{}", oneT, four);


    }
}
